package com.xiaoKe.zhonghzu.global.tool;

import android.text.TextUtils;

/**
 * @ProjectName : app
 * @Author : Shijingna
 * @Time : 2021/4/26 10:47 AM
 * @Description : 时间转换
 */
public class AgeUtiils {
    private static String hhh;
    private static String mmm;

    /**
     * @param time
     * @return 秒转换天小时分钟
     */
    public static String runningTime(long time) {//参数设置的时候单位为秒的
        long day = (time / (3600 * 24));
        long hour = (time % (3600 * 24)) / 3600;
        long min = time % 3600 / 60;
        if (day > 0) {
            return day + "d" + hour + "h" + min + "min";
        } else if (hour > 0) {
            return hour + "h" + min + "min";
        } else {
            return min + "min";
            //    智慧养殖数值化养殖方案
        }
    }

    /**
     * @param minute
     * @return 分钟转换天小时分钟
     */
    public static String runningTimeMin(long minute) {//参数设置的时候单位为秒的
        long d = minute / 60 / 24;
        long h = minute / 60 % 24;
        long m = minute % 60;
        String s1 = "";
        if (d > 0) {
            s1 = d + "d";
        }
        //h如果计算大于等于1再展示，否则只展示天和分钟
        if (h >= 1) {
            s1 += h + "h";
        }
        if (m > 0) {
            s1 += m + "min";
        }
        return s1;
    }

    /**
     * @param
     * @return //获取场家-品种
     */

    public static String getManufacturer(String manufacturer, String variety) {
        String strResult = "";
        if (!TextUtils.isEmpty(manufacturer) && !TextUtils.isEmpty(variety)) {
            strResult = manufacturer + "-" + variety;
        } else if (!TextUtils.isEmpty(manufacturer)) {
            strResult = manufacturer;
        } else if (!TextUtils.isEmpty(variety)) {
            strResult = variety;
        } else {
            strResult = "--";
        }
        return strResult;
    }


    /**
     * @param data
     * @return
     */
    // 时间转换
    public static String getTime(String data) {
        if (!TextUtils.isEmpty(data)) {
            int hh = Integer.parseInt(data.trim()) / 60;
            if (hh < 10) {
                hhh = "0" + hh;
            } else {
                hhh = "" + hh;
            }
            int mm = Integer.parseInt(data.trim()) % 60;
            if (mm < 10) {
                mmm = "0" + mm;
            } else {
                mmm = mm + "";
            }
            return hhh + ':' + mmm + "";

        } else {
            return "00:00";
        }

    }

    public static String getTime(int data) {
        int hh = data / 60;
        if (hh < 10) {
            hhh = "0" + hh;
        } else {
            hhh = "" + hh;
        }
        int mm = data % 60;
        if (mm < 10) {
            mmm = "0" + mm;
        } else {
            mmm = mm + "";
        }
        return hhh + ':' + mmm + "";


    }

    // 秒的单位
    public static String TimeSs(long time) {
        long hour = time / 3600;
        long min = time % 3600 / 60;
        if (hour > 0) {
            return hour + "h" + min + "min";
        } else {
            if (min == 0l) {
                return 1 + "min";
            } else {
                return min + "min";
            }

            //    智慧养殖数值化养殖方案
        }
    }

    // 分钟单位
    public static String timeMin(long time) {
        long hour = time / 60;
        long min = time % 60;
        if (hour > 0) {
            return hour + "h" + min + "min";
        } else {
            if (min == 0) {
                return 1 + "min";
            } else {
                return min + "min";
            }

            //    智慧养殖数值化养殖方案
        }
    }


    // 分钟单位
    public static String getTimeH(String data) {
        if (!TextUtils.isEmpty(data)) {
            int hhh = Integer.parseInt(data.trim()) / 60;
            int mmm = Integer.parseInt(data.trim()) % 60;
            if (hhh > 0) {
                return hhh + "h" + mmm;
            } else {
                return mmm + "min";
            }
        } else {
            return "";
        }

    }


    public static int getTimes(String data) {
        int i = 0;
        if (!TextUtils.isEmpty(data)) {
            String[] time = data.split(":");
            if (time.length == 2) {
                i = Integer.parseInt(time[0].equals("") ? "0" : time[0]) * 60 + Integer.parseInt(time[1]) * 1;
            }
        }

        return i;
    }


}
